<template>
  <view v-if="visible" class="dialog-mask">
    <view class="dialog">
      <view class="dialog-header">
        <text>{{ title }}</text>
      </view>
      <view class="dialog-content">
        <input type="text" v-model="inputValue"/>
      </view>
      <view class="dialog-footer">
        <button @click="close">取消</button>
        <button @click="confirm">确认</button>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: '请输入'
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      inputValue: ''
    };
  },
  methods: {
    close() {
      this.$emit('update:visible', false); // 关闭弹框
    },
    confirm() {
      this.$emit('confirm', this.inputValue); // 发射确认事件和输入的值
      this.close(); // 弹框确认后关闭
    }
  }
};
</script>

<style>
.dialog-mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
}
.dialog {
  background-color: #FFF;
  padding: 20px;
  border-radius: 5px;
}
.dialog-header {
  margin-bottom: 20px;
}
.dialog-footer {
  display: flex;
  justify-content: flex-end;
}
.dialog-footer button {
  margin-left: 10px;
}
</style>